#include "GLHeaders.hpp"
#include "ReferenceCube.hpp"

void ReferenceCube_::Draw(void){
	glCallList(list_id);
}

ReferenceCube_::ReferenceCube_(void){ 
	list_id = glGenLists(1); // create one DisplayList
	glNewList(list_id, GL_COMPILE);
	glPushAttrib(GL_COLOR_BUFFER_BIT|GL_CURRENT_BIT|GL_TEXTURE_BIT);	
	glDisable(GL_TEXTURE_2D);
	glBegin(GL_TRIANGLES);

	glNormal3f( 0.0f, 0.0f, 1.0f); // Front Face
	glColor3f(0.0f, 0.0f, 1.0f);glVertex3f(-0.5f,-0.5f, 0.5f);
	glColor3f(1.0f, 0.0f, 1.0f);glVertex3f( 0.5f,-0.5f, 0.5f);
	glColor3f(1.0f, 1.0f, 1.0f);glVertex3f( 0.5f, 0.5f, 0.5f);

	glColor3f(1.0f, 1.0f, 1.0f);glVertex3f( 0.5f, 0.5f, 0.5f);
	glColor3f(0.0f, 1.0f, 1.0f);glVertex3f(-0.5f, 0.5f, 0.5f);
	glColor3f(0.0f, 0.0f, 1.0f);glVertex3f(-0.5f,-0.5f, 0.5f);

	glNormal3f( 1.0f, 0.0f, 0.0f); // Right Face
	glColor3f(1.0f, 0.0f, 1.0f);glVertex3f( 0.5f,-0.5f, 0.5f);
	glColor3f(1.0f, 0.0f, 0.0f);glVertex3f( 0.5f,-0.5f,-0.5f);
	glColor3f(1.0f, 1.0f, 0.0f);glVertex3f( 0.5f, 0.5f,-0.5f);

	glColor3f(1.0f, 1.0f, 0.0f);glVertex3f( 0.5f, 0.5f,-0.5f);
	glColor3f(1.0f, 1.0f, 1.0f);glVertex3f( 0.5f, 0.5f, 0.5f);
	glColor3f(1.0f, 0.0f, 1.0f);glVertex3f( 0.5f,-0.5f, 0.5f);

	glNormal3f( 0.0f, 0.0f,-1.0f); // Back Face
	glColor3f(0.0f, 0.0f, 0.0f);glVertex3f(-0.5f,-0.5f,-0.5f);
	glColor3f(0.0f, 1.0f, 0.0f);glVertex3f(-0.5f, 0.5f,-0.5f);
	glColor3f(1.0f, 1.0f, 0.0f);glVertex3f( 0.5f, 0.5f,-0.5f);

	glColor3f(1.0f, 1.0f, 0.0f);glVertex3f( 0.5f, 0.5f,-0.5f);
	glColor3f(1.0f, 0.0f, 0.0f);glVertex3f( 0.5f,-0.5f,-0.5f);
	glColor3f(0.0f, 0.0f, 0.0f);glVertex3f(-0.5f,-0.5f,-0.5f);

	glNormal3f(-1.0f, 0.0f, 0.0f); // Left Face
	glColor3f(0.0f, 0.0f, 0.0f);glVertex3f(-0.5f,-0.5f,-0.5f);
	glColor3f(0.0f, 0.0f, 1.0f);glVertex3f(-0.5f,-0.5f, 0.5f);
	glColor3f(0.0f, 1.0f, 1.0f);glVertex3f(-0.5f, 0.5f, 0.5f);

	glColor3f(0.0f, 1.0f, 1.0f);glVertex3f(-0.5f, 0.5f, 0.5f);
	glColor3f(0.0f, 1.0f, 0.0f);glVertex3f(-0.5f, 0.5f,-0.5f);
	glColor3f(0.0f, 0.0f, 0.0f);glVertex3f(-0.5f,-0.5f,-0.5f);

	glNormal3f( 0.0f,-1.0f, 0.0f); // Under Face
	glColor3f(0.0f, 0.0f, 0.0f);glVertex3f(-0.5f,-0.5f,-0.5f);
	glColor3f(1.0f, 0.0f, 0.0f);glVertex3f( 0.5f,-0.5f,-0.5f);
	glColor3f(1.0f, 0.0f, 1.0f);glVertex3f( 0.5f,-0.5f, 0.5f);

	glColor3f(1.0f, 0.0f, 1.0f);glVertex3f( 0.5f,-0.5f, 0.5f);
	glColor3f(0.0f, 0.0f, 1.0f);glVertex3f(-0.5f,-0.5f, 0.5f);
	glColor3f(0.0f, 0.0f, 0.0f);glVertex3f(-0.5f,-0.5f,-0.5f);

	glNormal3f( 0.0f, 1.0f, 0.0f); // Top Face 
	glColor3f(0.0f, 1.0f, 0.0f);glVertex3f(-0.5f, 0.5f,-0.5f);
	glColor3f(0.0f, 1.0f, 1.0f);glVertex3f(-0.5f, 0.5f, 0.5f);
	glColor3f(1.0f, 1.0f, 1.0f);glVertex3f( 0.5f, 0.5f, 0.5f);

	glColor3f(1.0f, 1.0f, 1.0f);glVertex3f( 0.5f, 0.5f, 0.5f);
	glColor3f(1.0f, 1.0f, 0.0f);glVertex3f( 0.5f, 0.5f,-0.5f);
	glColor3f(0.0f, 1.0f, 0.0f);glVertex3f(-0.5f, 0.5f,-0.5f);
	glEnd();
	glPopAttrib();
	glEndList();
}

ReferenceCube_::~ReferenceCube_(void){
	glDeleteLists(list_id,1);
}
